/**
 *  Universidad del Valle de Guatemala
 *  Sección 20 Algoritmos y Estructuras de Datos
 *  Rudy Hernandez
 *  Diego Garcia
 *  Rodrigo Avelar 
 *  Interfaz gráfica que simula un radio para un carro
 */
public class caratula extends javax.swing.JFrame {

    /**
     * Creates new form caratula
     */
    public caratula() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton8 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        panel1 = new java.awt.Panel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        memoria1 = new javax.swing.JButton();
        memoria2 = new javax.swing.JButton();
        memoria3 = new javax.swing.JButton();
        memoria4 = new javax.swing.JButton();
        memoria5 = new javax.swing.JButton();
        memoria6 = new javax.swing.JButton();
        memoria7 = new javax.swing.JButton();
        memoria8 = new javax.swing.JButton();
        memoria9 = new javax.swing.JButton();
        memoria10 = new javax.swing.JButton();
        memoria11 = new javax.swing.JButton();
        memoria12 = new javax.swing.JButton();
        guardar = new javax.swing.JButton();
        sig = new javax.swing.JButton();
        bbandas = new javax.swing.JButton();

        jButton8.setText("jButton8");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(51, 153, 255));
        setResizable(false);

        jButton1.setText("ON/OFF");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        panel1.setBackground(new java.awt.Color(0, 0, 0));

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 417, Short.MAX_VALUE)
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 14, Short.MAX_VALUE)
        );

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        memoria1.setText("1");
        memoria1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria1ActionPerformed(evt);
            }
        });

        memoria2.setText("2");
        memoria2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria2ActionPerformed(evt);
            }
        });

        memoria3.setText("3");
        memoria3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria3ActionPerformed(evt);
            }
        });

        memoria4.setText("4");
        memoria4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria4ActionPerformed(evt);
            }
        });

        memoria5.setText("5");
        memoria5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria5ActionPerformed(evt);
            }
        });

        memoria6.setText("6");
        memoria6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria6ActionPerformed(evt);
            }
        });

        memoria7.setText("7");
        memoria7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria7ActionPerformed(evt);
            }
        });

        memoria8.setText("8");
        memoria8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria8ActionPerformed(evt);
            }
        });

        memoria9.setText("9");
        memoria9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria9ActionPerformed(evt);
            }
        });

        memoria10.setText("10");
        memoria10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria10ActionPerformed(evt);
            }
        });

        memoria11.setText("11");
        memoria11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria11ActionPerformed(evt);
            }
        });

        memoria12.setText("12");
        memoria12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memoria12ActionPerformed(evt);
            }
        });

        guardar.setText("SAVE");
        guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarActionPerformed(evt);
            }
        });

        sig.setText(">>");
        sig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sigActionPerformed(evt);
            }
        });

        bbandas.setText("AM/FM");
        bbandas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bbandasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bbandas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(64, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel1))))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(guardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sig))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(memoria1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(memoria8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(memoria9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria11, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(memoria12)))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bbandas)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(guardar)
                    .addComponent(sig))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(memoria1)
                    .addComponent(memoria2)
                    .addComponent(memoria3)
                    .addComponent(memoria4)
                    .addComponent(memoria5)
                    .addComponent(memoria6)
                    .addComponent(memoria7)
                    .addComponent(memoria8)
                    .addComponent(memoria9)
                    .addComponent(memoria10)
                    .addComponent(memoria12)
                    .addComponent(memoria11))
                .addGap(117, 117, 117)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {guardar, sig});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void memoria1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria1ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(1);
                save=false;
            }
            radio1.seleccionarEstacion(1);
        }
        pantalla();
    }//GEN-LAST:event_memoria1ActionPerformed

    private void memoria2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria2ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(2);
                save=false;
            }
            radio1.seleccionarEstacion(2);
        }
        pantalla();
    }//GEN-LAST:event_memoria2ActionPerformed
    private void pantalla (){
        if (radio1.isOn())
            if (radio1.isAM()) jTextField1.setText(radio1.getFrecuencia() +"AM");
            else jTextField1.setText(radio1.getFrecuencia()+"FM");
    }
    private void bbandasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bbandasActionPerformed
        if (radio1.isOn())
            radio1.cambiarBanda();
        pantalla();
            
    }//GEN-LAST:event_bbandasActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        radio1.onOff();
        jTextField1.setText("");
        pantalla();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void memoria3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria3ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(3);
                save=false;
            }
            radio1.seleccionarEstacion(3);
        }
        pantalla();
    }//GEN-LAST:event_memoria3ActionPerformed

    private void memoria4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria4ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(4);
                save=false;
            }
            radio1.seleccionarEstacion(4);
        }
        pantalla();
    }//GEN-LAST:event_memoria4ActionPerformed

    private void memoria5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria5ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(5);
                save=false;
            }
            radio1.seleccionarEstacion(5);
        }
        pantalla();
    }//GEN-LAST:event_memoria5ActionPerformed

    private void memoria6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria6ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(6);
                save=false;
            }
            radio1.seleccionarEstacion(6);
        }
        pantalla();
    }//GEN-LAST:event_memoria6ActionPerformed

    private void memoria7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria7ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(7);
                save=false;
            }
            radio1.seleccionarEstacion(7);
        }
        pantalla();
    }//GEN-LAST:event_memoria7ActionPerformed

    private void memoria8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria8ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(8);
                save=false;
            }
            radio1.seleccionarEstacion(8);
        }
        pantalla();
    }//GEN-LAST:event_memoria8ActionPerformed

    private void memoria9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria9ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(9);
                save=false;
            }
            radio1.seleccionarEstacion(9);
        }
        pantalla();
    }//GEN-LAST:event_memoria9ActionPerformed

    private void memoria10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria10ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(10);
                save=false;
            }
            radio1.seleccionarEstacion(10);
        }
        pantalla();
    }//GEN-LAST:event_memoria10ActionPerformed

    private void memoria11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria11ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(11);
                save=false;
            }
            radio1.seleccionarEstacion(11);
        }
        pantalla();
    }//GEN-LAST:event_memoria11ActionPerformed

    private void memoria12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoria12ActionPerformed
        if (radio1.isOn()){
            if (save){
                radio1.guardarEstacion(12);
                save=false;
            }
            radio1.seleccionarEstacion(12);
        }
        pantalla();
    }//GEN-LAST:event_memoria12ActionPerformed

    private void sigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sigActionPerformed
        if (radio1.isOn())
            radio1.cambiarFrecuencia();
        pantalla();
    }//GEN-LAST:event_sigActionPerformed

    private void guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarActionPerformed
        save=true;
    }//GEN-LAST:event_guardarActionPerformed
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(caratula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(caratula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(caratula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(caratula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new caratula().setVisible(true);
            }
        });
    }
    private RadioCarro radio1 = new RadioCarro();
    private boolean save = false;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bbandas;
    private javax.swing.JButton guardar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton memoria1;
    private javax.swing.JButton memoria10;
    private javax.swing.JButton memoria11;
    private javax.swing.JButton memoria12;
    private javax.swing.JButton memoria2;
    private javax.swing.JButton memoria3;
    private javax.swing.JButton memoria4;
    private javax.swing.JButton memoria5;
    private javax.swing.JButton memoria6;
    private javax.swing.JButton memoria7;
    private javax.swing.JButton memoria8;
    private javax.swing.JButton memoria9;
    private java.awt.Panel panel1;
    private javax.swing.JButton sig;
    // End of variables declaration//GEN-END:variables
}
